<?php

namespace app\index\model;

use think\Model;

class Assets extends Model
{
    protected $hidden =['category_id'];

    public function Category()
    {
        return $this->belongsTo('Category','category_id');
    }


    public static function get_assets_id()
    {
        $get_id = Project::get_project_id();
        $get_pip = Pipeline::get_pipeline_id($get_id) ;
        $get_cate = Category::get_category_id($get_pip) ;

        $get_ats  = self::where(['assets_name'=>input('assets_name'),'category_id' =>$get_cate['id']])->field('id')->find() ;
        if (isset($get_ats['id'])){
            return [1 ,array('assets_id' => $get_ats['id'], )];
        }else{
            return [0 , "not found"];
        }  
    }

    public static function get_data($data='')
    {
        return self::where($data)->order('id desc')->select();
    }

    public static function get_count($data='')
    {
        return self::where($data)->count();
    }

    public static function add_data()
    {
        $data_count = self::where(['assets_name'=>input('assets_name'),'category_id'=>input('category_id')])->count() ;
        if(!$data_count){
            return [1 , self::strict(false)->insert(input())];
        }else{
            return [0 , "data is repeat"];
        }

    }

    public static function update_data($data)
    {
        return self::update($data);
    }

     public static function delete_data($data='')
    {
        return self::where($data)->delete();
    }
}